package com.alks.function.controller.stockdept.pcfactorystockquery;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.factorywork.PcSupplementDetailRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.*;
import com.alks.function.service.common.BackService;
import com.alks.function.service.pcfactorywork.IPcSupplementService;
import com.alks.function.service.stockdept.pcfactorystockquery.IPcSubWorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

@RestController
@ApiRestController("/pcFactorStockQuery")
@Api(value = "仓储部查询",tags = "仓储部-仓储工厂作业-补单开单作业")
@RoleCheck(prgIds = {"160106"})
public class PcSubWorkController {
    @Autowired
    IPcSupplementService sService;

    @Autowired
    IPcSubWorkService workService;

    @PutMapping("/getSpHeadQuery")
    @ApiOperation(value = "补单开单作业-补料单资料查询-分页可条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpHeadQuery(@RequestBody SpHeadRequest request) {
        return workService.getSpHeadQuery(request);
    }

    @PostMapping("/getSpDetailQery")
    @ApiOperation(value = "补单开单作业-补制补料明细查询-条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpDetailQery(@RequestParam String slipNo) {
        return workService.getSpDetailQery(slipNo);
    }

    @PostMapping("/getSpDetailDelete")
    @ApiOperation(value = "补单开单作业-补制补料明细删除-删除", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpDetailDelete(@RequestParam@ApiParam("补料单号") String slipNo,
                                        @RequestParam@ApiParam("指令") String lotNo,
                                        @RequestParam@ApiParam("序号") String seqNo) {
        return workService.getSpDetailDelete(slipNo,lotNo,seqNo);
    }

    @PostMapping("/getNumberQery")
    @ApiOperation(value = "补单开单作业-客人大底号查询-条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getNumberQery(@RequestParam@ApiParam("补料单号") String slipNo,
                                      @RequestParam@ApiParam("指令")String lotNo,
                                      @RequestParam@ApiParam("型体")String style) {
        return workService.getNumberQery(slipNo,lotNo,style);
    }

    @PostMapping("/getSpDutyLotQuery")
    @ApiOperation(value = "补单开单作业-指令责任明细查询-条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpDutyLotQuery(@RequestParam@ApiParam("补料单号") String slipNo,
                                          @RequestParam@ApiParam("材料编号") String mtlNo) {
        PcSupplementDetailRequest request=new PcSupplementDetailRequest(slipNo,mtlNo);
        return sService.listSupplementLot(request);
    }

    @PostMapping("/getSpPartQuery")
    @ApiOperation(value = "补单开单作业-补料部位查询-条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpPartQuery(@RequestParam@ApiParam("指令") String lotNo) {
        return workService.getSpPartQuery(lotNo);
    }

    @PostMapping("/getSpPartAppQuery")
    @ApiOperation(value = "补单开单作业-补料部位追加查询-条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpPartAppQuery(@RequestParam@ApiParam("指令") String lotNo,
                                          @RequestParam@ApiParam("补料ID") String slipNo) {
        return workService.getSpPartAppQuery(lotNo,slipNo);
    }

    @PutMapping("/getSpPartSubQuery")
    @ApiOperation(value = "补单开单作业-开补子材料查询-条件查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSpPartSubQuery(@RequestBody SpPartSubRequest request) {
        return workService.getSpPartSubQuery(request);
    }

    @PutMapping("/spPartAdd")
    @ApiOperation(value = "补单开单作业-新增|追加补料部位-新增", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spPartAdd(@RequestBody SpPartRequest request) {
        return workService.spPartAdd(request);
    }

    @PostMapping("/spDetailAdd")
    @ApiOperation(value = "补单开单作业-计算补料明细-新增", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spMtlAdd(@RequestParam@ApiParam("补料单号") String slipNo) {
        return workService.spMtlAdd(slipNo);
    }

    @PutMapping("/spDetailCopyUpdate")
    @ApiOperation(value = "补单开单作业-补量复制-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spDetailCopyUpdate(@RequestBody SpDetailCopyReqiest request) {
        return workService.spDetailCopyUpdate(request);
    }

    @PostMapping("/spPrintUpdate")
    @ApiOperation(value = "补单开单作业-打印补料单-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spPrintUpdate(@RequestParam@ApiParam("补料单号") String slipNo) {
        return workService.spPrintUpdate(slipNo);
    }

    @PostMapping("/spTurnCfmUpdate")
    @ApiOperation(value = "补单开单作业-转审核-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spTurnCfmUpdate(@RequestParam@ApiParam(value = "补料单号",required = true) String slipNo,
                                        @RequestParam(required = false)@ApiParam("0.取消审核 1.审核") Integer type) {
        type=(type!=null&&type == 0)?0:1;
        return workService.spTurnCfmUpdate(slipNo,type);
    }

    @PostMapping("/getDutyFileQuery")
    @ApiOperation(value = "补单开单作业-责任建档查询-查询", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getDutyFileQuery(@RequestParam@ApiParam("1.责任厂商/员工 2.责任员工") Integer type) {
        return workService.getDutyFileQuery(type);
    }

    @PutMapping("/getDutyFileAdd")
    @ApiOperation(value = "补单开单作业-责任建档插入-新增", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getDutyFileAdd(@RequestBody List<DutyFileRequest> request,
                                       @RequestParam@ApiParam("1.责任厂商/员工 2.责任员工") Integer type) {
        return workService.getDutyFileAdd(request,type);
    }

    @PutMapping("/getDutyFileUpdate")
    @ApiOperation(value = "补单开单作业-责任建档数据更新-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getDutyFileUpdate(@RequestBody@Valid List<DutyFileRequest> request,
                                          @RequestParam@ApiParam(required = true,value = "1.责任厂商/员工 2.责任员工") Integer type) {
        return workService.getDutyFileUpdate(request,type);
    }


    @PutMapping("/dutyFileDelete")
    @ApiOperation(value = "补单开单作业-责任建档删除-删除", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo dutyFileDelete(@RequestBody DutyAddSub request,
                                          @RequestParam@ApiParam("1.责任厂商/员工 2.责任员工") Integer type) {
        return workService.dutyFileDelete(request,type);
    }

    @PutMapping("/dutyFileAdd")
    @ApiOperation(value = "补单开单作业-责任建档-新增", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo dutyFileAdd(@Valid @RequestBody DutyAddRequest request,
                                    @RequestParam(required = false)@ApiParam("责任数量") BigDecimal qty,
                                    @RequestParam@ApiParam(value = "0.责任厂商/员工 1.责任员工 2.责任厂商",required = true) Integer type,
                                    @RequestParam@ApiParam(value = "0.单材料分配 1.全部分配",required = true) Integer flag) {
        workService.dutyFileAdd(request,qty,type,flag);
        return ResponseInfo.ok();
    }

    @PutMapping("/dutyDetailDelete")
    @ApiOperation(value = "补单开单作业-责任明细删除-删除", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo dutyDetailDelete(@RequestBody DutyDtRequest request) {
        return workService.dutyDetailDelete(request);
    }

    @GetMapping("/dutyDetail/Clear")
    @ApiOperation(value = "补单开单作业-责任明细清空-删除", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo dutyDetailClear(@RequestParam @ApiParam("0.责任厂商/员工 1.责任员工") Integer type) {
        workService.dutyDetailClear(type);
        return ResponseInfo.ok();
    }

    @PutMapping("/spDetailUpdate")
    @ApiOperation(value = "补单开单作业-补制明细修改-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spDetailUpdate(@RequestBody List<SpDetailUpRequest> request,
                                       @RequestParam@ApiParam("尺码数量") Integer sizeNum) {
        return workService.spDetailUpdate(request,sizeNum);
    }

    @PostMapping("/spRemakrUpdate")
    @ApiOperation(value = "补单开单作业-备注说明修改-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spRemakrUpdate(@RequestParam@ApiParam("补料单号") String slipNo,
                                       @RequestParam@ApiParam("备注") String remark) {
        return workService.spRemakrUpdate(slipNo,remark);
    }

    @PostMapping("/parentComputer")
    @ApiOperation(value = "补单开单作业-平均分摊-数据处理", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo parentComputer(@RequestParam@ApiParam("0:责任厂商/员工 1.责任员工") Integer type) {
        workService.parentComputer(type);
        return ResponseInfo.ok();

    }

    @PostMapping("/spAllDelete")
    @ApiOperation(value = "补单开单作业-整单删除-删除", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spAllDelete(@RequestParam@ApiParam("补料单号") String slipNo) {
        return workService.spAllDelete(slipNo);
    }


    @PostMapping("/spHeadUpdate")
    @ApiOperation(value = "补单开单作业-补制类型修改-更新", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo spHeadUpdate(@RequestParam@ApiParam("补料单号") String slipNo,
                                     @RequestParam@ApiParam("补料单号") String slipType) {
        return workService.spHeadUpdate(slipNo,slipType);
    }

    @PostMapping("/spHead/invalid")
    @ApiOperation(value = "作废", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo invalid(@RequestParam@ApiParam("补料单号") String slipNo,
                                @RequestParam@ApiParam("Y 作废，N 取消作废") String invFlag) {
        workService.invalid(slipNo,invFlag);
        return ResponseInfo.ok();
    }

    @Autowired
    BackService backService;
    @PostMapping({"/complement/dept/combo"})
    @GetMapping
    @ApiOperation(value = "补单开单条件返回", tags = "仓储部-仓储工厂作业-补单开单作业")
    public ResponseInfo getSupplementDeptNo(String searchKey) {
        return backService.getSupplementDept(searchKey);
    }

}
